package com.javainterface.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * 添加到redis
 */
@Service
public class RedisDaoService {
    @Autowired
    RedisTemplate<String, String> redisTemplate;

    public String redisSet(String key, String value,String workStatus) {
        if (redisTemplate.hasKey(key)) {
            if (redisTemplate.opsForValue().get(key).equals(value)) {
                return "[" + key + "]value already exist";
            } else {
                redisTemplate.opsForValue().set(key, value);
                return "[" + key + "]value update success";
            }
        } else {
            redisTemplate.opsForValue().set(key, value);
            return "[" + key + "]key add success";
        }
    }
}
